package com.wandian.news.mvvm.lifetool.zgjm;

import android.os.Bundle;

import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.mylib.libcore.config.RouterConfig;
import com.mylib.libcore.mvvm.BaseMVVMActivity;
import com.mylib.libcore.utils.ActivityUtil;
import com.mylib.libcore.utils.ToastUtil;
import com.mylib.libcore.utils.UIUtils;
import com.wandian.news.R;
import com.wandian.news.adapter.LifeZGJMRecycleAdapter;
import com.wandian.news.databinding.NewsActivityLifeMedicineBinding;
import com.wandian.news.databinding.NewsActivityLifeZgjmBinding;

/**
 * @author Administrator
 * @date 2019/12/18-14:28
 * @description 周公解梦activity
 **/
@Route(path = RouterConfig.ROUTER_ACTIVITY_NEWS_ZGJM)
public class LifeZGJMActivity extends BaseMVVMActivity<LifeZGJMActivityViewModel>  {
    private NewsActivityLifeZgjmBinding dataBinding;
    private LifeZGJMRecycleAdapter adapter;

    @Override
    public void init(Bundle savedInstanceState) {
        dataBinding = DataBindingUtil.setContentView(this, R.layout.news_activity_life_zgjm);
        dataBinding.setLifecycleOwner(this);
        dataBinding.setViewModel(mViewModel);
        initViewData();
        initClink();
        initRecycle();

    }


    private void initViewData(){
        ActivityUtil.getInstance().showStatusView(this,dataBinding.viewSysTop,true);
        dataBinding.bindTransparentToolBar.toolBarTvTitle.setText("周公解梦");
        mViewModel.dataBean.observe(this,dataBean->{
            if(!UIUtils.isEmpty(dataBean)){
                adapter.setNewData(dataBean);
            }

        });
    }

    private void initClink(){
        dataBinding.bindTransparentToolBar.toolBarIvBack.setOnClickListener(v -> finish());

        dataBinding.tvSearch.setOnClickListener(v -> {
            finishhideSoftBoard();
           if(!UIUtils.isEmpty(dataBinding.etSearch.getText())){
               mViewModel.getData(dataBinding.etSearch.getText().toString());
           }else {
               ToastUtil.show("请输入关键字");
           }
        });
    }

    private void initRecycle(){
        adapter = new LifeZGJMRecycleAdapter(R.layout.news_item_life_zgjm_style);
        RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(this);
        dataBinding.recycler.setLayoutManager(layoutManager);
        dataBinding.recycler.setAdapter(adapter);

    }


    @Override
    protected void onDestroy() {
        finishhideSoftBoard();
        super.onDestroy();
    }
}
